package edu.gatech.cs2340.thecyclonesquad;

import edu.gatech.cs2340.thecyclonesquad.database.Database;
import edu.gatech.cs2340.thecyclonesquad.models.InMemoryModel;
import edu.gatech.cs2340.thecyclonesquad.models.Person;
import android.os.Build;
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;

public class CreateAdminActivity extends Activity {
	
	public final static String NEWADMIN_MESSAGE = "edu.gatech.cs2340.thecyclonesquad.USERNAMEI";
	
	//instance of inMemoryModel
	//InMemoryModel users = new InMemoryModel();
	
	

	@SuppressLint("NewApi")
	@Override
	/**
	 * Initializes our activity.
	 */
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_create_admin);
		// Make sure we're running on Honeycomb or higher to use ActionBar APIs
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            // Show the Up button in the action bar.
            getActionBar().setDisplayHomeAsUpEnabled(true);
        }
	}

	@Override
	/**
	 * Initialize the contents of the Activity's standard options menu.
	 */
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_create_admin, menu);
		return true;
	}
	
	/**
	 * Create admin button pressed.
	 * @param view is the basic building block for UI components
	 */
	public void adminCreated(View view) {
		EditText editText = (EditText) findViewById(R.id.username);
		String username = editText.getText().toString();
		EditText editText2 = (EditText) findViewById(R.id.password);
		String password = editText2.getText().toString();
		Database entry = new Database(this);
		entry.open();
		entry.createPerson(username, password, "true");
		entry.close();
		Intent intent = new Intent(this, AdminCreatedActivity.class);
		intent.putExtra(NEWADMIN_MESSAGE, username);
		startActivity(intent);
	}
	
	/**
	 * logOut method logs the user out and goes back to login page.
	 * @param view is the basic building block for UI components
	 */
	public void logOut(View view) {
		Intent intent = new Intent(this, SignInActivity.class);
		startActivity(intent);			
	}

}
